<?php

namespace App\Providers;

use App\DataProviders\AirportDataProvider;
use App\DataProviders\AirportDataProviderInterface;
use App\Services\AirportsSearchService;
use App\Services\ElasticsearchService;
use App\Services\SearchIndexServiceInterface;
use App\Services\SearchServiceInterface;
use Elastic\Elasticsearch\ClientBuilder;
use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Register any application services.
     */
    public function register(): void
    {
        $this->app->singleton(ElasticsearchService::class, function () {
            $client = ClientBuilder::create()
                ->setHosts(config('database.elasticsearch.hosts'))
                ->build();
            return new ElasticsearchService($client);
        });
        $this->app->singleton(SearchServiceInterface::class, AirportsSearchService::class);
        $this->app->singleton(SearchIndexServiceInterface::class, ElasticsearchService::class);
        $this->app->singleton(AirportDataProviderInterface::class, function () {
            return new AirportDataProvider(
                'https://raw.githubusercontent.com/NemoTravel/nemo.travel.geodata/master/airports.json'
            );
        });
    }

    /**
     * Bootstrap any application services.
     */
    public function boot(): void
    {
        //
    }
}
